<%--
  Created by IntelliJ IDEA.
  User: lichengming
  Date: 2017/8/17
  Time: 下午3:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/resources.jsp" %>

<html>
<head>
    <title>Title</title>
    <style type="text/css">
        .base_info {
            display: flex;
            justify-content: space-around;
        }
        .base_info_item {
            width: 50%;
        }
        .distribution_ratio {
            width: 80px;
            height: 80px;
            border-radius: 40px;
            border: 10px solid orange;
            text-align: center;
            line-height: 60px;
            margin: 0 auto;
            background-color: #716235;
            color: white;
        }
        .ratio_wrap {
            padding: 10px;
            margin-right: 10px;
            cursor: pointer;
        }


        .ratio_wrap_active {
            background-color: #739494;
        }


        .score_ratio_wrap {
            padding: 10px;
            margin-right: 10px;
            cursor: pointer;
        }

        .score_ratio_wrap_active {
            background-color: #739494;
        }

        .well label {
            font-weight: bold;
        }

        .search_area_agent {
            margin-top: 10px;
            width: 150px;
        }
        .search_result {
            margin-top: 10px;
            display: none;
        }

        .search_result img {
            height: 72px;
            width: 72px;
            border-radius: 72px;
        }
        .search_user_info {
            text-align: center;
            float: left;
            padding: 10px;
            cursor: pointer;
        }
        .search_user_info_select {
            background-color: rgba(244, 239, 138, 0.4);
        }
        .search_user_info p{
            margin-top: 5px;
            margin-bottom: 0;
        }
    </style>
</head>
<body>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">商家申请审核</h3>
        </div>

        <div class="panel-body">
            <div class="base_info well" style="width: 100%">
                <div class="panel-body base_info_item">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <h4>申请人基本信息</h4>
                            <div>
                                <p><label>昵称：</label>${record.user.nick_name}</p>
                                <p><label>注册时间：</label>${record.user.register_time}</p>
                                <p><label>手机号：</label>${record.user.phone}</p>
                                <p><label>地址：</label>${record.user.area}</p>
                                <p><label>是否已认证：</label>${record.user.is_auth}</p>
                                <c:if test="${record.user.status == 1}">
                                    <p><label>状态：</label><span style="color: forestgreen;font-weight: bold;">${record.user.status_str}</span></p>
                                </c:if>
                                <c:if test="${record.user.status == 0}">
                                    <p><label>状态：</label><span style="color: red;font-weight: bold;">${record.user.status_str}</span></p>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-body base_info_item">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <h4>合作伙伴基本信息</h4>
                            <div>
                                <p><label>合作伙伴：</label>${record.agent.real_name}</p>
                                <p><label>手机号：</label>${record.agent.phone}</p>
                                <p><label>缴纳费用：</label>${record.agent.pay_amount}</p>
                                <p><label>地址：</label>${record.agent.address}</p>
                                <p><label>邮箱：</label>${record.agent.email}</p>
                                <c:if test="${record.user.status == 1}">
                                    <p><label>状态：</label><span style="color: forestgreen;font-weight: bold;">${record.agent.status_str}</span></p>
                                </c:if>
                                <c:if test="${record.user.status == 0}">
                                    <p><label>状态：</label><span style="color: red;font-weight: bold;">${record.agent.status_str}</span></p>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="panel-body">
            <div class="panel panel-default">
                <div class="panel-body">
                    <h4>申请资料</h4>
                    <div class="well" style="width: 100%">
                        <p><label>姓名：</label>${record.real_name_}</p>

                        <p><label>申请时间：</label>${record.create_time_}</p>

                        <p><label>店铺名称：</label>${record.shop.store_name_}</p>

                        <p><label>店铺logo：</label></p>
                        <p>
                            <img src="${record.shop.logo_}">
                        </p>

                        <p><label>店铺类型：</label>${record.shop.business_type_}</p>

                        <p><label>店铺地址：</label>${record.shop.addr_}</p>

                        <p><label>创建时间：</label>${record.shop.create_time_}</p>

                        <p><label>身份证：</label>${record.identification_}</p>

                        <p><label>身份证正面照：</label>
                        </p>
                        <p>
                            <img src="${record.front_img_}" />
                        </p>

                        <p><label>身份证反面照：</label>
                        </p>
                        <p>
                            <img src="${record.opposite_img_}" />
                        </p>

                        <p><label>身份证手持照：</label></p>
                        <p>
                            <img src="${record.hand_img_}" />
                        </p>

                        <p><label>营业执照：</label>
                        </p>
                        <p>
                            <img src="${record.licence_img_}" />
                        </p>

                        <p><label>执照名：</label>${record.licence_name_}</p>

                        <p><label>执照号：</label>${record.licenc_no_}</p>

                        <p><label>执照所在地：</label>${record.licence_addr_}</p>

                        <p><label>执照有效期：</label>${record.licence_duration_}</p>

                        <p><label>执照类型：</label>${record.licence_type_}</p>

                        <p><label>推荐码：</label>${record.referral_code_}</p>

                        <p><label>合同编号：</label>${record.agreement_no_}</p>

                        <p><label>负责人手机号：</label>${record.man_phone_}</p>

                    </div>



                    <c:if test="${record.status_ == 'auditing'}">
                        <div class="well ratio_select">
                            <p>请点击选择<span style="font-size: 18px;font-weight: bold;color: red;">商家利润</span>让利比</p>
                            <div style="display: flex;justify-content: flex-start;flex-wrap: wrap;">
                                <c:forEach items="${ratioList}" var="ratio">
                                    <div class="ratio_wrap">
                                        <div class="distribution_ratio" rtid="${ratio.id}">${ratio.ratio}%</div>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>

                        <div class="well ratio_select">
                            <p>请点击选择<span style="font-size: 18px;font-weight: bold;color: red;">商家积分</span>让利比</p>
                            <div style="display: flex;justify-content: flex-start;flex-wrap: wrap;">
                                <c:forEach items="${ratioList}" var="ratio">
                                    <div class="score_ratio_wrap">
                                        <div class="distribution_ratio" rtid="${ratio.ratio}">${ratio.ratio}%</div>
                                    </div>
                                </c:forEach>
                            </div>
                        </div>

                        <div class="well clearfix">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属区县代理：</label>
                                <div class="col-sm-9">
                                    <input type="text" id="app_account" class="form-control" placeholder="请输入昵称或手机号查找(如无需关联，可不填写)">
                                    <button type="button" class="search_area_agent btn btn-primary">搜索区县代理</button>
                                    <div class="search_result panel panel-default">
                                        <div class="panel-body">
                                            <c:if test="${ not empty areaAgent.id}">
                                                <div class="search_user_info search_user_info_select" sid="${areaAgent.user.id}" >
                                                    <img src="${areaAgent.user.head_photo}" />
                                                    <p>${areaAgent.user.nick_name}</p>
                                                </div>
                                            </c:if>
                                            <c:if test="${empty areaAgent.id}">
                                                <div class="search_user_info"></div>
                                            </c:if>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="well">
                            <button type="button" id="audit_succeed" class="btn btn-success">审核通过</button>
                            <button type="button" id="audit_fail" class="btn btn-danger">审核不通过</button>
                        </div>

                    </c:if>

                    <c:if test="${record.status_ == 'audit_succeed'}">
                        <div class="well">
                            <p>分润让利比：</p>
                            <div class="ratio_wrap">
                                <div class="distribution_ratio" rtid="${record.ratio.id}">${record.ratio.ratio}%</div>
                            </div>
                            <p>积分让利比：</p>
                            <div class="ratio_wrap">
                                <div class="distribution_ratio" rtid="${record.ratio.id}">${record.ratio.sg_merchant_ratio}%</div>
                            </div>
                        </div>
                        <div class="well clearfix">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属区县代理：</label>
                                <div class="col-sm-9">
                                    <div class="search_result panel panel-default" <c:if test="${not empty areaAgent.id}">style="display: block" </c:if>>
                                        <div class="panel-body">
                                            <c:if test="${not empty areaAgent.id}">
                                                <div class="search_user_info search_user_info_select" sid="${areaAgent.id}" >
                                                    <img src="${areaAgent.head_photo}" />
                                                    <p>${areaAgent.nick_name}</p>
                                                </div>
                                            </c:if>
                                            <c:if test="${empty areaAgent.id}">
                                                <div class="search_user_info"></div>
                                            </c:if>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </c:if>
                </div>
            </div>
        </div>
</div>

<script>

    $(".ratio_wrap").on("click",function () {
        $(this).siblings().removeClass("ratio_wrap_active");
        $(this).toggleClass("ratio_wrap_active");
    })

    $(".score_ratio_wrap").on("click",function () {
        $(this).siblings().removeClass("score_ratio_wrap_active");
        $(this).toggleClass("score_ratio_wrap_active");
    })

    $(".search_area_agent").bind("click",function () {
        $.emsAjax({
            url:"/ems/areaagent/search",
            data:{searchName:$("#app_account").val()},
            success:function (resp) {
                if (resp.status != "000") {
                    $.errorAlert(resp.message);
                    return;
                }else {
                    $(".search_user_info").remove();
                    $(".search_result").show();
                    $(".search_result").find(".panel-body")
                        .append('<div class="search_user_info" sid="'+resp.data.id+'"><img src="'+resp.data.head_photo+'"> <p>'+resp.data.nick_name+'</p></div>');
                    $(".search_user_info").on("click",function () {
                        $(this).toggleClass("search_user_info_select");
                    });
                }
            }
        })
    });

    $("#audit_succeed").on("click",function () {

        var $ratio = $(".ratio_wrap_active");
        if ($ratio.length == 0) {
            $.toast("请选择商家分润让利比","cancel");
            return;
        }

        var $score_ratio = $(".score_ratio_wrap_active");
        if ($score_ratio.length == 0) {
            $.toast("请选择商家积分让利比","cancel");
            return;
        }

        var data = {};
        data["ratio_id"] = $ratio.children().attr("rtid");
        data["id"] = '${record.id_}';
        data["status"] = 1;
        data["sg_merchant_ratio"] = parseFloat($score_ratio.children().attr("rtid")) /100.0;

        $serach_user = $(".search_user_info_select");
        if ($serach_user.length > 0) {
            data["area_agent_id"] = $serach_user.attr("sid");
        }


        $.emsAjax({
            url:"/ems/merchant/auditUpdate",
            data:data,
            type:"POST",
            success:function (resp) {
                if (resp.status == "000") {
                    $.toast(resp.message,function () {
                        window.location.href = "/ems/merchant/index"
                    });
                }else {
                    $.toast(resp.message,"text");
                }
            }
        })
    });

    $("#audit_fail").on("click",function () {
        $.emsAjax({
            url:"/ems/merchant/auditUpdate",
            data:{status:0,id:'${record.id_}'},
            type:"POST",
            success:function (resp) {
                if (resp.status == "000") {
                    $.toast(resp.message,function () {
                        window.location.href = "/ems/merchant/index"
                    });
                }else {
                    $.toast(resp.message,"cancel");
                }
            }
        })
    });


</script>
</body>
</html>
